<?php include _include(APP_PATH . 'view/admin/htm/header.inc.htm'); ?>
<link rel="stylesheet" type="text/css" href="./admin/view/vendor/datatables/css/dataTables.bootstrap4.css">
<div class="row">
    <div class="col-12">
        <div class="page-header" id="top">
            <h2 class="pageheader-title">产品服务</h2>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <form action="<?php echo url('shopadmin-contact')?>" method="POST" id="form">
                    <div class="table-responsive arrlist">
                        <table class="table table-striped table-bordered first" style="min-width: 400px">
                            <thead>
                                <th>选择帖子</th>
                                <th>删除</th>
                            </thead>
                            <tbody id="tbody">
                                <?php foreach($clist as $c) {?>
                                <tr>
                                    <td><select class="form-control" id='tid' name="tid[]">
                                        <?php foreach($threadlist as $k => $v){ ?>
                                        <option value="<?php echo $v['tid'] ?>" <?php if($v['tid'] == $c){echo 'selected';}?> ><?php echo $v['subject'] ?></option>
                                        <?php } ?>
                                    </select></td>
                                    <td><a class="row_delete">删除</a></td>
                                </tr>
                                <?php } ?>
                            </tbody>
                        </table>
                    </div>
                    <p><a role="button" class="btn row_add">[+]添加一行</a></p>
                    <p class="text-center">
                        <button type="submit" class="btn btn-primary" id="submit" data-loading-text="<?php echo lang('submiting');?>..." style="width: 10rem;">保存</button>
                    </p>
                </form>
            </div>
        </div>
    </div>
</div>

<?php include _include(APP_PATH . 'view/admin/htm/footer.inc.htm'); ?>

<script>

var jform = $("#form");
var jsubmit = $("#submit");


jform.on('submit', function(){
	jform.reset();
	var postdata = jform.serialize();
	jsubmit.button('loading');
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			jsubmit.text(message).delay(3000).location();
			return;
		} else {
			alert(message);
			jsubmit.button('reset');
		}
	});
	return false;
});


var tbody = $('#tbody')
var jadd = $('a.row_add');
var jarrlist = $('.arrlist');
jadd.click(function(){
    var jclone = jarrlist.find('tr').last().clone();
    jclone.insertAfter(jarrlist.find('tr').last());
	//var rowid = xn.intval(jfid.val()) + 1;

	return false;
})

var jdelete = $('a.row_delete');
jarrlist.on('click', 'a.row_delete', function() {
	var jthis = $(this);
	var jtr = jthis.parents('tr');
	jtr.remove();
	return false;
});

</script>